package com.example;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.stage.Stage;

public class StudentAcademicInformationController implements StudentSubController {

    @FXML
    private TextField usernameField;
    @FXML
    private TextField nameField;
    @FXML
    private TextField typeField;
    @FXML
    private TextField departmentField;
    @FXML
    private TextField majorField;
    @FXML
    private TextField studentClassField;
    @FXML
    private TextField enrollmentDateField;
    @FXML
    private Button backButton;

    private Stage primaryStage;
    private StudentController studentController;
    private User currentUser;

    @Override
    public void setPrimaryStage(Stage primaryStage) {
        this.primaryStage = primaryStage;
    }

    @Override
    public void setStudentController(StudentController studentController) {
        this.studentController = studentController;
    }

    public void setCurrentUser(User user) {
        System.out.println("StudentAcademicInformationController: setCurrentUser called with user: " + (user != null ? user.getUsername() : "null"));
        this.currentUser = user;
        populateFields();
    }

    private void populateFields() {
        System.out.println("StudentAcademicInformationController: populateFields called.");
        if (currentUser != null) {
            usernameField.setText(currentUser.getUsername());
            nameField.setText(currentUser.getName());
            typeField.setText(currentUser.getType());
            departmentField.setText("信息工程学院");

            // 解除注释，使用User类的新增方法填充字段
            // majorField.setText(currentUser.getMajor());
            // studentClassField.setText(currentUser.getStudentClass());
            // enrollmentDateField.setText(currentUser.getEnrollmentDate());

            majorField.setText("计算机科学与技术专业");
            studentClassField.setText("5");
            enrollmentDateField.setText("待补充");

            // 临时打印学籍信息，用于调试
            System.out.println("User Academic Info:");
            // System.out.println("  Major: " + currentUser.getMajor());
            // System.out.println("  Class: " + currentUser.getStudentClass());
            // System.out.println("  Enrollment Date: " + currentUser.getEnrollmentDate());
            System.out.println("--------------------");

            // 删除或注释掉占位符
            // majorField.setText("待补充"); // 占位符
            // studentClassField.setText("待补充"); // 占位符
            // enrollmentDateField.setText("待补充"); // 占位符

        }
    }

    @FXML
    private void handleBack() {
        if (studentController != null) {
            // 调用 StudentController 的方法显示学生主界面的默认视图
            studentController.showStudentHomeView();
        } else {
            System.err.println("studentController is null");
        }        
    }
} 